{% extends "base.html" %}
{% block title %}用户交易记录{% end %}
{% block content %}
<div class="pace  pace-inactive">
    <div class="pace-progress" data-progress-text="100%" data-progress="99" style="width: 100%;">
        <div class="pace-progress-inner"></div>
    </div>
    <div class="pace-activity"></div>
</div>
<div id="wrapper">
    {% include 'admin_nav.html' %}
    <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
            {% include 'header_nav.html' %}
        </div>
        <div class="row wrapper border-bottom white-bg page-heading">
            <div class="col-lg-10">
                <h2>用户管理</h2>
                <ol class="breadcrumb">
                    <li>
                        <a href="/admin/home">主页</a>
                    </li>
                    <li>
                        <a>{{user.get('username')}}的转账记录</a>
                    </li>

                </ol>
            </div>
            <div class="col-lg-2">

            </div>
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>转账记录
                            </h5>
                            <div class="ibox-tools">
                                <a class="collapse-link">
                                    <i class="fa fa-chevron-up"></i>
                                </a>

                                <a class="close-link">
                                    <i class="fa fa-times"></i>
                                </a>
                            </div>
                        </div>
                        <div class="ibox-content">
                            <style>
                                th:first-child,
                                .gradeX td:first-child {
                                    width: 20px;
                                    cursor: pointer;
                                }

                                th:first-child input,
                                .gradeX td:first-child input {
                                    cursor: pointer;
                                }
                            </style>


                            <form action="javascript:;" method="post" name="login_form" id="login_form">
                                {% module xsrf_form_html() %}
                                <table class="table table-striped table-bordered table-hover dataTables-example">
                                    <thead>
                                    <tr>

                                        <th>充值用户UID</th>
                                        <th>金额</th>
                                        <th>交易时间</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {% for u in trade_records %}
                                    <tr class="gradeX">
                                        <th>{{u.get('mid','无')}}</th>
                                        <td>{{u.get('money',0)}}</td>
                                        <td>{{u.get('time','未知')}}</td>
                                    </tr>
                                    {% end %}
                                    </tbody>
                                </table>




                            </form>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>


    $(function () {


        var json1 = _alert('.btn.btn-w-m.delete1', '.modal-body .delete1Content', '您要删除的用户ID为');
        var json2 = _alert('.btn.btn-w-m.audit1', '.modal-body .audit1Content', '您要拉入黑名单的用户ID为');

        var list_to_handle;

        $('tr.gradeX input[type="checkbox"],#userListCheck').click(function () {
            list_to_handle = listNubmer()
            console.log(listNubmer());
        });

        function getCookie(name) {
            var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
            return r ? r[1] : undefined;
        }

        $.ajaxSetup({
            beforeSend: function (xhr, settings) {
                if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type)) {
                    xhr.setRequestHeader("X-XSRFToken", getCookie("_xsrf"));
                }
            }
        });

        $('.btn.btn-white.deleteUserId').click(function () {
            $.ajax({
                url: '/admin/userlist',
                type: 'delete',
                data: list_to_handle,
                success: function (data) {
                    console.log(data);
                },
                error: function () {
                    alert('error');
                }
            });
        });

        $('.btn.btn-white.auditUserId').click(function () {
            $.ajax({
                url: '/admin/userlist',
                type: 'put',
                data: list_to_handle,
                success: function (data) {
                    console.log(data);
                },
                error: function () {
                    alert('error');
                }
            });
        });
        var focus_money = 0;
        $(".reset_pwd_protect").click(function () {
            var base_url = "/admin/reset_pwd_protect?uid=";
            var uid = $(this).data("uid");
            var tip = "警告!您确定要重置用户uid为" + uid + "的密保吗?";
            if (confirm(tip)) {
                window.location = base_url + uid;
                return true;
            }
            return false;
        })
        $(".money_td").focus(function () {
            focus_money = $(this).text();
        })
        $(".money_td").blur(function () {

            if ($(this).text() != focus_money) {
                var data={};
                var that=$(this);
                data['money']=$(this).text();
                data['uid']=$(this).data("handle-id");
                if (confirm("确认修改该用户激活币吗？")) {
                    $.ajax({
                        url: '/admin/update_money',
                        type: 'post',
                        data:data ,
                        success: function (data) {
                            var j=jQuery.parseJSON(data);
                            if(j.status=='ok'){
                                 alert ("修改成功")
                            }
                            else{
                                alert (j.error);
                                that.text(focus_money);
                            }
                        },
                        error: function () {
                            alert('error');
                        }
                    });
                }
            }
        })
    });
</script>

{% end %}